﻿package mortal.game.view.group.panel
{
    import Message.Public.*;
    import com.greensock.layout.*;
    import com.mui.controls.*;
    import extend.language.*;
    import fl.data.*;
    import flash.display.*;
    import flash.events.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.scene3D.layer3D.utils.*;
    import mortal.game.scene3D.player.info.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.button.*;
    import mortal.game.view.group.cellRenderer.*;
    import mortal.mvc.core.*;

    public class NearPlayerPanel extends GSprite
    {
        private var _playerList:GTileList;
        private var _refreshBtn:GButton;
        private var _inviteAllBtn:TimeButton;

        public function NearPlayerPanel()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.pushUIToDisposeVec(UIFactory.bg(13, 65, 778, 325, this, ImagesConst.PanelBg));
            this.pushUIToDisposeVec(UIFactory.bg(10, 66, 788, 22, this, ImagesConst.RegionTitleBg));
            var _loc_1:* = GlobalStyle.textFormatPutong;
            _loc_1.align = AlignMode.CENTER;
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(30218), 0, 67, 160, 20, this, _loc_1));
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(30219), 160, 67, 100, 20, this));
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(30220), 280, 67, 100, 20, this));
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(30217), 390, 67, 100, 20, this));
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(30221), 530, 67, 100, 20, this));
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(30216), 695, 67, 100, 20, this));
            this._playerList = UIFactory.tileList(22, 93, 750, 287, this);
            this._playerList.rowHeight = 30;
            this._playerList.columnWidth = 740;
            this._playerList.horizontalGap = 1;
            this._playerList.verticalGap = 1;
            this._playerList.setStyle("skin", new Bitmap());
            this._playerList.setStyle("cellRenderer", NearPlayerCellRenderer);
            this.addChild(this._playerList);
            this._refreshBtn = UIFactory.gButton(Language.getString(30210), 315, 396, 65, 22, this);
            this._refreshBtn.configEventListener(MouseEvent.CLICK, this.refreshList);
            this._inviteAllBtn = UIFactory.timeButton(Language.getString(30249), 415, 396, 65, 22, this);
            this._inviteAllBtn.cdTime = 5000;
            this._inviteAllBtn.configEventListener(MouseEvent.CLICK, this.inviteAll);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._playerList.dispose(param1);
            this._refreshBtn.dispose(param1);
            this._inviteAllBtn.dispose(param1);
            this._playerList = null;
            this._refreshBtn = null;
            this._inviteAllBtn = null;
            super.disposeImpl(param1);
            return;
        }// end function

        private function getDateProvider() : DataProvider
        {
            var _loc_3:EntityInfo = null;
            var _loc_4:Object = null;
            var _loc_1:* = new DataProvider();
            var _loc_2:* = Cache.instance.entity.getAllEntityInfo();
            _loc_2.sort(this.sortOnLevelAndPower);
            for each (_loc_3 in _loc_2)
            {
                
                if (_loc_3.entityInfo.career > 0 && _loc_3.entityInfo.entityId.type == EEntityType._EEntityTypePlayer && _loc_3.entityInfo.groupId.id == 0 && _loc_3.entityInfo.ownerEntityId && _loc_3.entityInfo.ownerEntityId.id == 0)
                {
                    _loc_4 = {data:_loc_3};
                    _loc_1.addItem(_loc_4);
                }
            }
            return _loc_1;
        }// end function

        private function sortOnLevelAndPower(param1:EntityInfo, param2:EntityInfo) : int
        {
            var _loc_3:* = Cache.instance.role.entityInfo.entityId;
            if (EntityUtil.isSameServer(_loc_3, param1.entityInfo.entityId) && !EntityUtil.isSameServer(_loc_3, param2.entityInfo.entityId))
            {
                return -1;
            }
            if (!EntityUtil.isSameServer(_loc_3, param1.entityInfo.entityId) && EntityUtil.isSameServer(_loc_3, param2.entityInfo.entityId))
            {
                return 1;
            }
            if (param1.entityInfo.combat > param2.entityInfo.combat)
            {
                return -1;
            }
            if (param1.entityInfo.combat < param2.entityInfo.combat)
            {
                return 1;
            }
            return 0;
        }// end function

        private function refreshList(event:MouseEvent) : void
        {
            this.updatePlayerList();
            return;
        }// end function

        private function inviteAll(event:MouseEvent) : void
        {
            var _loc_4:SGroupOper = null;
            var _loc_6:int = 0;
            var _loc_2:* = Cache.instance.entity.getAllEntityInfo();
            var _loc_3:* = _loc_2.length >= 8 ? (8) : (_loc_2.length);
            var _loc_5:* = new Array();
            while (_loc_6 < _loc_3)
            {
                
                if ((_loc_2[_loc_6] as EntityInfo).entityInfo.entityId.type == EEntityType._EEntityTypePlayer && (_loc_2[_loc_6] as EntityInfo).entityInfo.groupId.id == 0 && (_loc_2[_loc_6] as EntityInfo).entityInfo && (_loc_2[_loc_6] as EntityInfo).entityInfo.ownerEntityId.id == 0 && EntityUtil.isSelfProxy((_loc_2[_loc_6] as EntityInfo).entityInfo.entityId) && EntityUtil.isSameServerByRole((_loc_2[_loc_6] as EntityInfo).entityInfo.entityId))
                {
                    _loc_4 = new SGroupOper();
                    _loc_4.fromEntityId = Cache.instance.role.entityInfo.entityId;
                    _loc_4.toEntityId = (_loc_2[_loc_6] as EntityInfo).entityInfo.entityId;
                    _loc_4.fromPlayer = new SPublicPlayer();
                    _loc_4.fromPlayer.entityId = Cache.instance.role.entityInfo.entityId;
                    _loc_4.type = EGroupOperType._EGroupOperTypeInvite;
                    _loc_4.fromPlayer.guildId = new SEntityId();
                    _loc_4.fromPlayer.copyId = new SEntityId();
                    _loc_5.push(_loc_4);
                }
                _loc_6++;
            }
            if (_loc_5.length > 0)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.GroupInviteOper, _loc_5));
            }
            return;
        }// end function

        public function updatePlayerList() : void
        {
            this._playerList.dataProvider = this.getDateProvider();
            this._playerList.drawNow();
            return;
        }// end function

    }
}
